Refactor ConvertGenericCallExpr#145
Open
lucic71 wants to merge 2 commits into
Open
Conversation
nunoplopes
requested changes
May 24, 2026
| using Kind = CallArg::Kind; | ||
|
|
||
| unsigned arg_begin = 0; // skip count for operator()'s implicit object arg | ||
| CallInfo info{}; |
| } | ||
| } | ||
|
|
||
| void Converter::EmitCall(CallInfo info) { |
| Materialized, | ||
| }; | ||
|
|
||
| clang::Expr *expr; |
Contributor
There was a problem hiding this comment.
usually these are sorted by size (larger to shorter) to reduce struct size.
| std::optional<TempMaterializationCtx> ConvertCallExpr(clang::CallExpr *expr); | ||
|
|
||
| struct CallArg { | ||
| enum class Kind { |
| case Kind::Hoisted: | ||
| StrCat("let", | ||
| std::format("_{}: {}", ca.param_name, ToString(ca.param_type)), | ||
| "="); |
| bool is_variadic; | ||
| bool is_fn_ptr_call; | ||
| std::vector<CallArg> args; | ||
| std::vector<clang::Expr *> variadic_args; |
Contributor
There was a problem hiding this comment.
there's only up to one variadic arg. this can be a simple pointer initialized to null
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ConvertGenericCallExpr is a messy function and it became difficult to add new functoinality on top of it. So I decided to refactor it into:
EmitCall(CollectCallInfo(expr)).In the near future I plan to add 3 new features on top of it:
In the new version of ConvertGenericCallExpr, CollectCallInfo is responsible for returning the call information:
And EmitCall is responsible for emitting the hoisted arguments, the callee and the argument list using a CallInfo.
This model makes the addition of new strategies, for example
Don't hoist arguments that are integer literals, they don't alias with any other argument, easier because only the CallInfo fields have to be modified.